'use strict';

module.exports = app => {
  const { TEXT, STRING, INTEGER, DATE } = app.Sequelize;

  const Goods = app.model.define('goods', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    user_id: {
      type: INTEGER(64),
      allowNull: false,
      comment: '用户id',
    },
    title: {
      type: STRING(255),
      allowNull: true,
      comment: '商品标题',
    },
    content: {
      type: TEXT,
      allowNull: true,
      comment: '商品描述',
    },
    address: {
      type: STRING(255),
      allowNull: true,
      comment: '商品发布地址',
    },
    latitude: {
      type: STRING(255),
      allowNull: true,
      comment: '纬度',
    },
    longitude: {
      type: STRING(255),
      allowNull: true,
      comment: '经度',
    },
    heat: {
      type: STRING(255),
      allowNull: true,
      defaultValue: 0,
      comment: '热度',
    },
    contact: {
      type: STRING(255),
      allowNull: true,
      comment: '商品联系方式',
    },
    price: {
      type: STRING(255),
      allowNull: true,
      comment: '商品价格',
    },
    category: {
      type: INTEGER(30),
      allowNull: true,
      comment: '商品类别',
    },
    imgs: {
      type: TEXT,
      allowNull: true,
      comment: '商品图片',
    },
    created_at: DATE,
    updated_at: DATE,
  }, {
    sequelize: app.Sequelize,
    modelName: 'goods',
    tableName: 'goods',
    freezeTableName: true
  });

  return Goods;
};